package view;
import java.util.Observable;
import java.util.Scanner;

import model.algorithm.Action;
import model.base.Solution;

public class MyConsoleView extends Observable implements View {			//MyConsoleView is a sort of Observable that implements View
	private String act;
	
	@Override
	public void start() {
		System.out.println("Hello Folks! =]");							// CMD Line printing - Lame User menu - Hopefully temporary
																		// For now we want the user to enter the exact strings due to the fact that this 
																		// program doesn't deal with exceptions and validity check for input
																		// (Had no time because of a week of hospitalization) - fix later on!
		act = "";
		Scanner scanner = new Scanner(System.in);		// Simple text scanner that gets standard input 
		System.out.println("Those are your options:\n");
		System.out.println("SelectDomain 8Puzzle:123456708 (Example State. You can supply any other solvable StateString)");
		System.out.println("         ------------------------OR----------------------");
		System.out.println("         SelectDomain Maze:5,5,3 (Height, Width, No. of walls in the maze)");
		System.out.println("\n                    And then:\n\n "
							+ "SelectAlgorithm AStar:8Puzzle       SelectAlgorithm AStar:Maze");
		System.out.println("         ------------------------OR----------------------");
		System.out.println("                        SelectAlgorithm Bfs\n\n");
		System.out.println("Enter 'SolveDomain' To let the algorithm solve the domain");
		System.out.println("To End Program enter 'exit'");
		
		do
		{
			
			System.out.println("Please Enter Your Command: ");			
			act = scanner.nextLine();									// Gets data from user (Hopefully the exact string)
			
			if (!(act.equals("exit"))){		// if the user wants to continue with the program	
				this.setChanged();		// raising the changed "flag" and notifying all the observers that its up
				this.notifyObservers();
			}
						
		} while (!(act.equals("exit")));
		scanner.close();
	}

	
	
	@Override
	public void displayCurrentState() {					// no need with the algorithms and domains that i chose
		// TODO Auto-generated method stub				// this func could have get State s as a parameter
	}
	@Override
	public String getUserAction() {						// returns String - represent an action
		return act;
	}

	@Override
	public void displaySolution(Solution solution) {	// runs on the actions arraylist that the solution holds and prints every action
		for(Action act: solution.getActions())
			System.out.println(act);
	}
}
